package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetMealDTO;
import com.sky.dto.SetMealPageQueryDTO;
import com.sky.entity.SetMeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetMealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealMapper {
    // 根据分类id查询套餐
    @Select("select count(*) from setmeal where category_id = #{id}")
    int selectByCategoryId(Long id);

    // 新增套餐
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into setmeal(category_id, name, price, description, image, create_time, update_time, create_user, update_user) " +
            "values(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(SetMeal setMeal);

    //套餐条件分页查询
    Page<SetMealVO> queryPageOnConditional(SetMealPageQueryDTO setMealPageQueryDTO);

    //根据id集合查询起售状态的套餐数量
    int selectByIdAndStatus(List<Long> ids);

    //批量删除套餐
    void deleteBatchByIds(List<Long> ids);

    //根据id查询套餐
    SetMealVO getById(Long id);

    //修改套餐
    @AutoFill(OperationType.UPDATE)
    void update(SetMeal setMeal);
}
